Inside Macintosh: QuickTime

Previous | Chapter Top | Chapter Contents | Next

Getting a Movie From a File

Before your application can work with a movie, you must load the movie from its file. Your application must open the movie file and create a new movie from the movie stored in the file. You can then work with the movie. Use the OpenMovieFile function (described on OpenMovieFile ) to open a movie file. Use the NewMovieFromFile function (described on NewMovieFromFile ) to load a movie from a movie file. The code in Listing 2 shows how you can use these functions.

Listing 2 Getting a movie from a file

Movie GetMovie (void)
{
    OSErr                   err;
    SFTypeList              typeList = {MovieFileType,0,0,0};
    StandardFileReply       reply;
    Movie                   aMovie = nil;
    short                   movieResFile;

    StandardGetFilePreview (nil, 1, typeList, &reply);
    if (reply.sfGood)
    {
        err = OpenMovieFile (&reply.sfFile, &movieResFile,
                                    fsRdPerm);
        if (err == noErr)
        {
            short           movieResID = 0;         /* want first movie */
            Str255          movieName;
            Boolean         wasChanged;
        
            err = NewMovieFromFile (&aMovie, movieResFile,
                                            &movieResID,
                                            movieName,
                                            newMovieActive,         /* flags */
                                            &wasChanged);
            CloseMovieFile (movieResFile);
        }
    }
    return aMovie;
}

QuickTime movies are stored in movie files. The Movie Toolbox uses the features of the Alias Manager and the new File Manager functions to manage a movie's references to its data (see "The Movie Toolbox and System 6" which begins on The Movie Toolbox and System 6 for more information about these features). A movie file does not necessarily contain the movie's data. The movie's data may reside in other files, which are referred to by the movie file.

When your application instructs the Movie Toolbox to play a movie, the toolbox attempts to collect the movie's data. If the movie has become separated from its data, the Movie Toolbox uses the features of the Alias Manager to locate the data files. During this search, the Movie Toolbox automatically displays a dialog box similar to that shown in Figure 26 . The user can cancel the search by clicking the Stop button.

Figure 26 A dialog box used when searching for a movie's data

The Movie Toolbox performs a number of tests to verify that the file selected by the user is appropriate for the current movie. These tests include checking the creation date of the found file against the expected date and checking the size of the found file. The Movie Toolbox displays a dialog box similar to the one shown in Figure 27 .

Figure 27 A dialog box that informs the user the movie file cannot be found

The user has two options:

If the Movie Toolbox cannot locate a needed file, it displays a dialog box that allows the user to specify a file to try. Figure 28 shows a sample dialog box.

Figure 28 A dialog box that allows the user to specify a movie file to try

If the user chooses a file that is not a valid movie file, it displays an alert similar to the one shown in Figure 29 .

Figure 29 An alert for an invalid movie file

Figure 30An alert when QuickTime cannot be found


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next